﻿/* 2011/12/2 */
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace PictureManager
{
    public partial class RenameFolderForm : Form
    {
        private RenameFolderForm()
        {
            InitializeComponent();
        }

        public RenameFolderForm(string folderName)
            : this()
        {
            nameTextBox.Text = folderName;
        }

        private bool CheckFolderName()
        {
            string folderName = nameTextBox.Text;
            foreach (char aChar in Path.GetInvalidPathChars())
            {
                if (folderName.Contains(aChar.ToString()))
                {
                    MessageBox.Show(String.Format("文件夹名称不允许包含 {0}", aChar), "重命名失败");
                    return false;
                }
            }
            return true;
        }

        private void nameTextBox_KeyDown(object sender, KeyEventArgs e)
        {
            if ((e.KeyCode == Keys.Enter) && CheckFolderName())
                DialogResult = DialogResult.OK;
        }

        private void confirmButton_Click(object sender, EventArgs e)
        {
            if (CheckFolderName())
                DialogResult = DialogResult.OK;
        }

        private void cancelButton_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
        }

        public string FolderName
        {
            get { return nameTextBox.Text; }
            set { nameTextBox.Text = value; }
        }

    }
}
